<?php
namespace Admin\Controller;
//轮播图分类配置

use Common\Controller\AdminbaseController;

class SysbannerkindController extends AdminbaseController{

	protected $sys_model;

	public function _initialize() {
		parent::_initialize();
		$this->sys_model = D("Common/SysBannerKind");
	}

	// 轮播图分类列表
	public function index(){
		/**搜索条件**/
		$city_name = I('request.city_name');
		if($city_name){
			$where['city_name'] = array('like',"%$city_name%");
		}

		$count=$this->sys_model->where($where)->count();
		$page = $this->page($count, 10);
        $list = $this->sys_model
            ->where($where)
            ->order("id DESC")
            ->limit($page->firstRow, $page->listRows)
            ->select();
		$this->assign("page", $page->show('Admin'));
        $this->assign('list',$list);
		$this->display();
	}

	// 轮播图分类添加
	public function add(){
        $city = array(array('city_id'=>0,'city_name'=>'上海'));
        $this->assign('city',$city);
		$this->display();
	}

	// 轮播图分类添加提交
	public function add_post(){
		if(IS_POST){
            if ($this->sys_model->create() !== false) {
                $date = $_POST;
                /*当前管理员name*/
                $date['create_user'] = get_current_admin_name();
                $date['create_time'] = get_admin_time();
                $result = $this->sys_model->add($date);
                if ($result !== false) {
                    $this->success("添加成功！", U("Sysbannerkind/index"));
                } else {
                    $this->error("添加失败！");
                }
            } else {
                $this->error($this->sys_model->getError());
            }

		}
	}

	// 轮播图分类编辑
	public function edit(){
	    $id = I('get.id',0,'intval');
		$sys = $this->sys_model->where(array('id' => $id))->find();
        $city = array(array('city_id'=>0,'city_name'=>'上海'));
        $this->assign('city',$city);
		$this->assign('sys',$sys);
		$this->display();
	}

	// 轮播图分类编辑提交
	public function edit_post(){
		if (IS_POST) {
            if ($this->sys_model->create() !== false) {
                $date = $_POST;
                /*当前管理员name*/
                $date['update_user'] = get_current_admin_name();
                $date['update_time'] = get_admin_time();
                $result = $this->sys_model->save($date);
                if ($result !== false) {
                    $this->success("编辑成功！", U("Sysbannerkind/index"));
                } else {
                    $this->error("编辑失败！");
                }
            } else {
                $this->error($this->sys_model->getError());
            }

		}
	}

	// 轮播图删除
	public function delete(){
	    $id = I('get.id',0,'intval');
		if ($this->sys_model->delete($id)!==false) {
			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}
}